﻿using System.Collections.Generic;
using System.Runtime.Serialization;
using ProxyTool.Setting;

namespace ProxyTool.Models
{
    /// <summary>
    ///     上下文信息
    /// </summary>
    [DataContract]
    public class ContextInfo
    {
        /// <summary>
        ///     企业ID
        /// </summary>
        [DataMember]
        public string EnterpriseID { get; set; }

        /// <summary>
        ///     组织编码
        /// </summary>
        [DataMember]
        public string OrgCode { get; set; }

        /// <summary>
        ///     用户编码
        /// </summary>
        [DataMember]
        public string UserCode { get; set; }

        /// <summary>
        ///     密码
        /// </summary>
        [DataMember]
        public string Password { get; set; }

        /// <summary>
        ///     语言
        /// </summary>
        [DataMember]
        public string Culture { get; set; } = "zh-CN";

        /// <summary>
        ///     支持语言列表，多个中间用,分隔
        /// </summary>
        [DataMember]
        public string SupportCultureNameList { get; set; } = "zh-CN";

        public static ContextInfo GetContext()
        {
            ContextInfo contextInfo = new ContextInfo();
            contextInfo.EnterpriseID = SettingManagement.Instance.Setting.EnterpriseID;
            contextInfo.OrgCode = SettingManagement.Instance.Setting.OrgCode;
            contextInfo.UserCode = SettingManagement.Instance.Setting.UserCode;
            contextInfo.Password = SettingManagement.Instance.Setting.Password;
            contextInfo.Culture = SettingManagement.Instance.Setting.Culture;
            List<string> cultureNameList = new List<string>();
            if (SettingManagement.Instance.Setting.CultureList != null &&
                SettingManagement.Instance.Setting.CultureList.Count > 0)
            {
                foreach (LanguageData languageData in SettingManagement.Instance.Setting.CultureList)
                {
                    cultureNameList.Add(languageData.Code);
                }
            }
            else
            {
                cultureNameList.Add(SettingManagement.Instance.Setting.Culture);
            }

            contextInfo.SupportCultureNameList = string.Join(",", cultureNameList);
            return contextInfo;
        }
    }
}